package org.budo.mybatis.dao.statement.builder.creator;

import org.apache.ibatis.session.Configuration;
import org.budo.mybatis.dao.statement.builder.impl.DefaultStatementBuilder;

/**
 * @author lmw
 */
public class DeleteByIdStatementCreator extends AbstractStatementCreator {
    public DeleteByIdStatementCreator(Configuration configuration, DefaultStatementBuilder statementBuilder) {
        super(configuration, statementBuilder);
    }

    protected String getStatementId() {
        return STATEMENT_DELETE_BY_ID;
    }

    protected String createStatement(Class<?> entityType) {
        String tableName = this.getStatementBuilder().getEntityConfiger().getTableName(entityType);
        String idColumn = this.getStatementBuilder().getEntityConfiger().getIdColumn(entityType);
        Class<?> idType = this.getStatementBuilder().getEntityConfiger().getIdFieldType(entityType);

        String statementXml = _4 + "<delete id=\"" + this.getStatementId() + "\" parameterType=\"" + idType.getName() + "\">\n" //
                + _8 + "DELETE FROM " + tableName + " WHERE " + idColumn + "=#{id}" + "\n"//
                + _4 + "</delete>"; //

        return statementXml;
    }
}